package main

import (
	"fmt"
	"go-tour/pkg/reflect_util"
	"reflect"
)

type roles struct {
	roleId   int
	roleName string
}
type User struct {
	Name      string
	Age       int
	Email     string
	NickName  string
	Telephone int
	Salary    float64
	Roles     roles
}

func main() {
	u := User{Name: "mzi", Age: 30, Email: "xxxx@afanty3d.com", NickName: "omni360", Telephone: 123456789,
		Salary: 5555.56,
		Roles:  roles{roleId: 1001, roleName: "administrator"}}
	fmt.Println(u)
	Info(u)

}

func Info(o interface{}) {
	t := reflect.TypeOf(o)
	fmt.Println("Type:", t.Name())

	//v := reflect.ValueOf(o)
	fmt.Println("Fileds:")
	for i := 0; i < t.NumField(); i++ {
		f := t.Field(i)
		//val := v.Field(i).Interface()
		fieldName := reflect_util.Camel2Case(f.Name)
		val := reflect_util.ReflectGetFieldValue(o, fieldName)
		fmt.Printf("%20s(%10s) : %v %v\n", f.Name, fieldName, f.Type, val)

	}
}
